//
//  JLServerTool.m
//  PaySDKDemo
//
//  Created by LZ on 2018/8/14.
//  Copyright © 2018年 JLPAY. All rights reserved.
//

#import "JLServerTool.h"

#import <AdSupport/AdSupport.h>
#import "PaySDKConfig.h"
#import "JLSingleton.h"

static NSString *appVersion = nil;

@implementation JLServerTool

+ (NSString *)appBuildVersion{
    
    if (appVersion.length < 1) {
        
        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
        appVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
    }
    return appVersion;
}


+ (NSDictionary *)baseParamWithType:(NSString *)type{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"app_id"] = jlAppId;
    //设备唯一标识
    NSString *uuId = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
    param[@"phone_device_no"] = uuId;
    param[@"conn_type"]       = type;
    param[@"version"]         = [self appBuildVersion];
    param[@"session_id"]      = JLSingleton.share.sessionId;
    
    NSString *timeString      = [NSString stringWithFormat:@"%ld",(long)([[NSDate date] timeIntervalSince1970]*1000)];
    param[@"time_stamp"]      = timeString;
    param[@"latitude"]        = @"31.2363429624";
    param[@"longitude"]       = @"121.4803295328";
    
    return param.copy;
}

+ (NSString*)jsonStrByJsonObj:(id)object
{
    NSString *jsonString = nil;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}


@end
